//
//  //  柳州微博
//
//  Created by Apple_Lzzy40 on 16/9/18.
//  Copyright © 2016年 Apple_Lzzy40. All rights reserved.
//

#import "ZQViewController.h"
#import "ZQXiaoXiTableViewController.h"
#import "ZQWoTableViewController.h"
#import "ZQHomeViewController.h"
#import "ZQFaXianTableViewController.h"
#import "ZQWoTableViewController.h"
#import "ZQNavigationController.h"
#import "ZQTabBar.h"
#import "ZQComposeViewController.h"
//1.遵守协议
@interface ZQViewController() <ZQTabBarDelegate>

@end
@interface ZQViewController ()

@end

@implementation ZQViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //3.创建子控制
    ZQHomeViewController *vc1=[[ZQHomeViewController alloc]init];
    
   vc1.navigationItem.title = @"首页";
    [self SetChildVC:vc1 title:@"首页" image:@"tabbar_home" selectImage:@"tabbar_home_selected"];
    
   ZQXiaoXiTableViewController *vc2=[[ZQXiaoXiTableViewController alloc]init];
    
    vc2.navigationItem.title=@"消息";
    [self SetChildVC:vc2 title:@"消息" image:@"tabbar_message_center" selectImage:@"tabbar_message_center_selected"];
    
    ZQFaXianTableViewController *vc3=[[ZQFaXianTableViewController alloc]init];
    
    vc3.navigationItem.title=@"发现";
    [self SetChildVC:vc3 title:@"发现" image:@"tabbar_discover" selectImage:@"tabbar_discover_selected"];
    
    
    
   ZQWoTableViewController *vc4=[[ZQWoTableViewController alloc]init];
    vc4.navigationItem.title=@"我";
    [self SetChildVC:vc4 title:@"我" image:@"tabbar_profile" selectImage:@"tabbar_profile_selected"];
    
    //添加一个Button 到tarbar
    UIButton * plusBtn=[[UIButton alloc]init];
    [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    
    [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    
    [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    
    //设置图片的尺寸为原图尺寸
    plusBtn.size=plusBtn.currentBackgroundImage.size;
    plusBtn.centerX=self.tabBar.width * 0.5;
  // plusBtn.centerY=self.tabBar.height * 0.5;
    
    [self.tabBar addSubview:plusBtn];
    
    //更换系统的tabBar  kvc
    ZQTabBar * tabBar=[[ZQTabBar alloc]init];
    
    //2.指定代理方法
    tabBar.touchDelegate=self;
    
    [self setValue:tabBar forKeyPath:@"tabBar"];
    

}
//3.添加“+”方法
- (void)TabbarDidClickPlusButton:(ZQTabBar *)tabBar
{
    //发微博控制器
    ZQComposeViewController *compose =[[ZQComposeViewController alloc]init];
    
    //导航控制器
    ZQNavigationController *nav =[[ZQNavigationController alloc]initWithRootViewController:compose];
    [self presentViewController:nav animated:YES completion:nil];
    
}


-(void) SetChildVC:(UIViewController *)childVC  title  :(NSString *)title  image:(NSString *)image  selectImage:(NSString *)selectImage
{
    childVC.tabBarItem.title=title;
    childVC.tabBarItem.image=[UIImage imageNamed:image];
    UIImage * selectImage1=[UIImage imageNamed:selectImage];
    
    childVC.tabBarItem.selectedImage=[selectImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //修改背景颜色
    //childVC.view.backgroundColor= LWRandowColor;
    
    //通常
    NSMutableDictionary *textAttributes=[NSMutableDictionary dictionary];
    textAttributes[NSForegroundColorAttributeName]=[UIColor blueColor];
    
    //选中
    NSMutableDictionary *selectTextAttrbutes=[NSMutableDictionary dictionary];
    selectTextAttrbutes[NSForegroundColorAttributeName]=[UIColor grayColor];
    
    
    [childVC.tabBarItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
    [childVC.tabBarItem setTitleTextAttributes:selectTextAttrbutes forState:UIControlStateSelected];
    // 4.添加到根控制器中
   // UINavigationController * Nav=[[UINavigationController alloc]initWithRootViewController:childVC];
    ZQNavigationController *Nav=[[ZQNavigationController alloc]initWithRootViewController:childVC];
    [self addChildViewController:Nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
